parser grammar C;
import Ccore;
import CVocab;



typedef
	: compound_type ';'
	| 'typedef' {$declaration::isTypedef=true;} specifiers symbol (',' symbol)* ';'    -> ^(TYPEDEF specifiers symbol)+
	;

type_specifier
	:  struct_specifier
	| enum_specifier
	;

compound_type
	: 'struct' IDENTIFIER (struct_body)?
				-> ^(TYPEDEF ^(TYPE 'struct' struct_body?) IDENTIFIER)
	| 'union' IDENTIFIER (struct_body)?
	| 'enum' IDENTIFIER (enum_body )?
	;
struct_specifier
	: ('struct'|'union') struct_body
	| ('struct'|'union') IDENTIFIER
	| ('struct'|'union') IDENTIFIER struct_body
	;
enum_specifier
	: 'enum' enum_body
	| 'enum' IDENTIFIER
	| 'enum' IDENTIFIER enum_body
	;
struct_body scope SymbolTable;
@init{
	$SymbolTable::name="Compound type scope";
	$SymbolTable::types=new HashSet<String>();
}	: '{' struct_declaration+ '}'                         -> ^(COMPOUND struct_declaration+)
	;
struct_declaration
	: specifiers struct_declarator (',' struct_declarator)*
	;
struct_declarator
	: declarator
	;

